<template>
  <div class="container">
    <div class="search">
      <div class="search-input">
        <img class="search-input-icon" src="@/assets/imgs/item2.png" alt="" />
        <el-input
          v-model.trim="keyword"
          @keypress.native.enter="productSearchList"
        ></el-input>
        <img
          class="search-input-clear"
          src="@/assets/imgs/close-b.png"
          alt=""
          @click="clearKeyword"
        />
      </div>
      <div class="search-list">
        <div
          class="search-list-item"
          v-for="item in dataList"
          :key="item.id"
          @click="handleShowVideo(item.videoUrl)"
        >
          <img class="icon" src="@/assets/imgs/arrow.png" alt="" />
          <div class="item-right">
            <el-tooltip effect="dark" :content="item.title" placement="top">
              <div class="title">
                {{ item.title }}
              </div>
            </el-tooltip>

            <div class="des">
              <span class="text">{{ item.expert }}</span>
              <span class="text" v-if="item.company.trim()">,</span>
              <span class="text">{{ item.company }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      title=""
      :visible.sync="dialogVisible"
      width="840px"
      :before-close="handleClose"
    >
      <video
        ref="videoPlay"
        controls
        class="video-player"
        :src="videoUrl"
        autoplay="true"
      ></video>
    </el-dialog>
  </div>
</template>

<script>
import api from "servicePath/index"
import { mapState, mapMutations } from "vuex";

export default {
  data () {
    return {
      keyword: "",
      dataList: [],
      dialogVisible: false,
      videoUrl: ""
    }
  },
  computed: {
    ...mapState(["lang"])
  },
  watch: {
    lang () {
      this.productSearchList()
    }
  },
  mounted () { },
  methods: {

    ...mapMutations(["changeLang", "isShowLogin"]),
    async productSearchList () {
      // const params = {
      //   keyword: this.keyword
      // }
      if (this.keyword === "") return
      const res = await api.getScheduleSearch(this.keyword, this.lang)
      this.dataList = res.data
      console.log(res)
    },
    clearKeyword () {
      this.keyword = ""
    },
    handleClose (done) {
      done()
      this.$refs.videoPlay.pause()
    },
    handleShowVideo (videoUrl) {
      let isLogin = sessionStorage.getItem("vrToken");
      if (!isLogin) {
        this.isShowLogin("show");
        return;
      }
      this.dialogVisible = true
      this.videoUrl = videoUrl
    }
  }
};
</script>

<style lang="scss" scoped>
.search {
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;

  &-input {
    display: flex;
    align-items: center;
    position: relative;
    margin-bottom: 51px;
    &-icon {
      position: absolute;
      top: 50%;
      left: 0;
      transform: translateY(-50%);
      width: 25px;
      height: 25px;
    }
    &-clear {
      width: 28.28px;
      height: 28.28px;
      padding: 5px;
    }
    .el-input {
      width: 480px;
      border: 0;
      border-bottom: 1px solid #343434;
      padding: 15px 10px 15px 43px;

      font-size: 24px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #555555;
    }
    /deep/ .el-input__inner {
      border: 0;
      padding: 0;
    }
  }
  &-list {
    &-item {
      width: 500px;
      height: 77px;
      background: #f8f8f8;
      box-shadow: 0px 4px 11px 0px rgba(0, 0, 0, 0.13);
      border-radius: 4px;
      padding: 0 24px 0 12px;

      display: flex;
      overflow: hidden;

      & + .search-list-item {
        margin-top: 25px;
      }
      .icon {
        width: 17px;
        height: 17px;
        padding-left: 5px;
        margin-top: 16px;
        margin-right: 12px;
      }
      .item-right {
        flex: 1;
        overflow: hidden;
        .title {
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 28px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #555555;
          line-height: 40px;
          height: 50px;
          margin-top: 3px;
        }
        .des {
          font-size: 0;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #aeaeae;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;

          height: 20px;
          line-height: 20px;
          transform: translateY(-5px);
          .text {
            font-size: 14px;
          }
        }
      }
    }
  }
}
.video-player {
  width: 800px;
  height: 450px;
  // margin-top: 30px;
  background-color: #333333;
  margin: 0 auto;
}
</style>
